{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入工具包\n",
    "import numpy as np\n",
    "import pandas as pd \n",
    "from sklearn.metrics import mean_squared_error\n",
    "# metrics.mean_squared_error(y_true, y_pred[, …]) 用法：Mean squared error regression loss\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>mnth_1</th>\n",
       "      <th>mnth_2</th>\n",
       "      <th>mnth_3</th>\n",
       "      <th>mnth_4</th>\n",
       "      <th>mnth_5</th>\n",
       "      <th>...</th>\n",
       "      <th>weekday_5</th>\n",
       "      <th>weekday_6</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>holiday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>yr</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.355170</td>\n",
       "      <td>0.373517</td>\n",
       "      <td>0.828620</td>\n",
       "      <td>0.284606</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.379232</td>\n",
       "      <td>0.360541</td>\n",
       "      <td>0.715771</td>\n",
       "      <td>0.466215</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.171000</td>\n",
       "      <td>0.144830</td>\n",
       "      <td>0.449638</td>\n",
       "      <td>0.465740</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.175530</td>\n",
       "      <td>0.174649</td>\n",
       "      <td>0.607131</td>\n",
       "      <td>0.284297</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.209120</td>\n",
       "      <td>0.197158</td>\n",
       "      <td>0.449313</td>\n",
       "      <td>0.339143</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 35 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant  season_1  season_2  season_3  season_4  mnth_1  mnth_2  mnth_3  \\\n",
       "0        1         1         0         0         0       1       0       0   \n",
       "1        2         1         0         0         0       1       0       0   \n",
       "2        3         1         0         0         0       1       0       0   \n",
       "3        4         1         0         0         0       1       0       0   \n",
       "4        5         1         0         0         0       1       0       0   \n",
       "\n",
       "   mnth_4  mnth_5  ...  weekday_5  weekday_6      temp     atemp       hum  \\\n",
       "0       0       0  ...          0          1  0.355170  0.373517  0.828620   \n",
       "1       0       0  ...          0          0  0.379232  0.360541  0.715771   \n",
       "2       0       0  ...          0          0  0.171000  0.144830  0.449638   \n",
       "3       0       0  ...          0          0  0.175530  0.174649  0.607131   \n",
       "4       0       0  ...          0          0  0.209120  0.197158  0.449313   \n",
       "\n",
       "   windspeed  holiday  workingday  yr   cnt  \n",
       "0   0.284606        0           0   0   985  \n",
       "1   0.466215        0           0   0   801  \n",
       "2   0.465740        0           1   0  1349  \n",
       "3   0.284297        0           1   0  1562  \n",
       "4   0.339143        0           1   0  1600  \n",
       "\n",
       "[5 rows x 35 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取数据\n",
    "df = pd.read_csv(\"FE_day.csv\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 35 columns):\n",
      " #   Column        Non-Null Count  Dtype  \n",
      "---  ------        --------------  -----  \n",
      " 0   instant       731 non-null    int64  \n",
      " 1   season_1      731 non-null    int64  \n",
      " 2   season_2      731 non-null    int64  \n",
      " 3   season_3      731 non-null    int64  \n",
      " 4   season_4      731 non-null    int64  \n",
      " 5   mnth_1        731 non-null    int64  \n",
      " 6   mnth_2        731 non-null    int64  \n",
      " 7   mnth_3        731 non-null    int64  \n",
      " 8   mnth_4        731 non-null    int64  \n",
      " 9   mnth_5        731 non-null    int64  \n",
      " 10  mnth_6        731 non-null    int64  \n",
      " 11  mnth_7        731 non-null    int64  \n",
      " 12  mnth_8        731 non-null    int64  \n",
      " 13  mnth_9        731 non-null    int64  \n",
      " 14  mnth_10       731 non-null    int64  \n",
      " 15  mnth_11       731 non-null    int64  \n",
      " 16  mnth_12       731 non-null    int64  \n",
      " 17  weathersit_1  731 non-null    int64  \n",
      " 18  weathersit_2  731 non-null    int64  \n",
      " 19  weathersit_3  731 non-null    int64  \n",
      " 20  weekday_0     731 non-null    int64  \n",
      " 21  weekday_1     731 non-null    int64  \n",
      " 22  weekday_2     731 non-null    int64  \n",
      " 23  weekday_3     731 non-null    int64  \n",
      " 24  weekday_4     731 non-null    int64  \n",
      " 25  weekday_5     731 non-null    int64  \n",
      " 26  weekday_6     731 non-null    int64  \n",
      " 27  temp          731 non-null    float64\n",
      " 28  atemp         731 non-null    float64\n",
      " 29  hum           731 non-null    float64\n",
      " 30  windspeed     731 non-null    float64\n",
      " 31  holiday       731 non-null    int64  \n",
      " 32  workingday    731 non-null    int64  \n",
      " 33  yr            731 non-null    int64  \n",
      " 34  cnt           731 non-null    int64  \n",
      "dtypes: float64(4), int64(31)\n",
      "memory usage: 200.0 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备\n",
    "y = df[\"cnt\"]\n",
    "X = df.drop([\"cnt\"],axis=1)\n",
    "\n",
    "feat_names = X.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(147, 34)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=33,test_size = 0.2)\n",
    "X_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The RSME score of LinearRegression on test is 814.474907686365\n",
      "The RSME score of LinearRegression on train is 742.7543512758713\n"
     ]
    }
   ],
   "source": [
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "lr = LinearRegression()\n",
    "\n",
    "lr.fit(X_train,y_train)\n",
    "\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by = ['coef'], ascending = False)\n",
    "\n",
    "print ('The RSME score of LinearRegression on test is', np.sqrt(mean_squared_error(y_test, y_test_pred_lr)))\n",
    "print ('The RSME score of LinearRegression on train is', np.sqrt(mean_squared_error(y_train, y_train_pred_lr)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The RSME score of RidgeCV on test is 812.0412682483411\n",
      "The RSME score of RidgeCV on train is 747.4410131599831\n"
     ]
    }
   ],
   "source": [
    "# 岭回归\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#1. 设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#2. 生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#3. 模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#4. 预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用RSME评价模型在测试集和训练集上的性能\n",
    "print ('The RSME score of RidgeCV on test is', np.sqrt(mean_squared_error(y_test, y_test_pred_ridge)))\n",
    "print ('The RSME score of RidgeCV on train is', np.sqrt(mean_squared_error(y_train, y_train_pred_ridge)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ4AAAEGCAYAAABVSfMhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3deXRU55nn8e8jCbHvCLEjHPACdkywArYhTtLEYLuTOLbjhDg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B8GHASqA/L3dzJfnKAts+I7grbT2Q4UBnOuL5JrJ11m0vJjLuTS5bRGY9IejxH7PObd4mdhfwnd68ys2eAhcR+wH9ArPNjfVjnd8SC6CV3f9fM3iZ29+IPgQ2d7OckMMvMtoTtfPUCdT0EPGNmdwKvhPXbfDbUINKjdHdqkYiZ2RCPdZ0cTewsaH4IpYHEwmB++GwomW2dcPchPVTX68Ct7n6kJ7Yn0kZnPCLR+62ZjQDygR+5exWAu582sweI9bbfl86CwuXAf1boSCrojEdERNJKkwtERCStFDwiIpJWCh4REUkrBY+IiKSVgkdERNLq/wPacMu3ewxnZQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 1.0\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The RSME score of LassoCV on test is 813.4148635007385\n",
      "The RSME score of LassoCV on train is 743.1893104872604\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 126204783.36529711, tolerance: 176331.28855032122\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 127247277.965017, tolerance: 176331.28855032122\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 126871725.60688312, tolerance: 176331.28855032122\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 130913437.06329168, tolerance: 171396.26788522486\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 130445067.50041239, tolerance: 171396.26788522486\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 130180213.6225748, tolerance: 171396.26788522486\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 123571134.86040238, tolerance: 178645.74666680943\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 124414891.62598993, tolerance: 178645.74666680943\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 123741141.24939473, tolerance: 178645.74666680943\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 126013565.80717637, tolerance: 172687.4240346895\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 125498587.51288608, tolerance: 172687.4240346895\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 90386143.52883564, tolerance: 169474.6999863248\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 125386121.15828735, tolerance: 169474.6999863248\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:472: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 125303750.4866788, tolerance: 169474.6999863248\n",
      "  tol, rng, random, positive)\n",
      "d:\\python\\lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:476: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Duality gap: 162249010.15987134, tolerance: 217175.10367928082\n",
      "  positive)\n"
     ]
    }
   ],
   "source": [
    "# Lasso回归\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#2. 生成学习器实例\n",
    "lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#Lasso可以自动确定最大的alpha，所以另一种设置alpha的方式是设置最小的alpha值（eps） 和 超参数的数目（n_alphas），\n",
    "#然后LassoCV对最小值和最大值之间在log域上均匀取值n_alphas个\n",
    "# np.logspace(np.log10(alpha_max * eps), np.log10(alpha_max),num=n_alphas)[::-1]\n",
    "\n",
    "#2 生成LassoCV实例（默认超参数搜索范围）\n",
    "# lasso = LassoCV()  \n",
    "\n",
    "#3. 训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#4. 测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用REME_score评价模型在测试集和训练集上的性能\n",
    "print ('The RSME score of LassoCV on test is', np.sqrt(mean_squared_error(y_test, y_test_pred_lasso)))\n",
    "print ('The RSME score of LassoCV on train is', np.sqrt(mean_squared_error(y_train, y_train_pred_lasso)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ4AAAEGCAYAAABVSfMhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3de3Bc5Znn8e8jyfLdli/yTZIvxIaAARssfIMQJk5sJ5PFQCA4AazKMMMmxdQkMzW1gc3WeDeZ2g2b2VDFzCa77JDCMvcQCEwS4jhAwsxYvsjGxjYGbLBkyTa2jCz5Luvy7B/9tt0Ssloy6j5S9+9T1dVH73nf9zznWO5H55y3z2vujoiISLrkRB2AiIhkFyUeERFJKyUeERFJKyUeERFJKyUeERFJq7yoA+gPxo4d61OnTo06DBGRfmXz5s1H3L2wY7kSTzdMnTqVysrKqMMQEelXzKy6s3JdahMRkbRS4hERkbRS4hERkbRS4hERkbRS4hERkbRS4hERkbRS4hERkbRS4hERkY850HCa//HKLuqON/V630o8IiLyMU9t2Mejb3zAmebWXu9biUdERNppamnl6Y37WPTp8ZSMHtLr/SvxiIhIO7/ZfpCPTp6lbOGUlPSvxCMiIu2sW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jaHNr4klot+7+zYze5PY04s/AP79Ats5Ccw0s82hnzuTxPUT4Bdmdgfwemgf9ychBpFepadTi0TMzIZ5bNbJMcTOgq4PSWkwsWRwfbg31J2+Trj7sF6K6w1gmbsf7Y3+ROJ0xiMSvV+ZWQGQD/zA3T8EcPfTZraS2Nz2+9IZULgc+GMlHUkFnfGIiEhaaXCBiIiklRKPiIiklRKPiIiklRKPiIiklRKPiIik1f8HDoZwXMIlAkAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.1\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过观察模型评价指标可以看出，在训练集上评价最好的是岭回归模型，其次是Lasso模型，最后是最小二乘线性回归。原因是岭回归和Lasso都在最小二乘线性回归模型中加入了正则项，防止了模型过拟合的问题，所以效果要更好些。而在特征分析中，我们看到有很多特征相关性比较大，比如说温度与体感温度，在特征多，且特征间存在共线性关系时使用L2正则效果要更好，所以这这里岭回归模型比Lasso回归又好一点点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
